package com.gitee.zjbqdzq.core;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public abstract class Downloader {

    protected final String saveFolder;

    protected Downloader(String saveFolder) throws IOException {
        this.saveFolder = saveFolder;
        checkSaveFolder();
    }

    public abstract void download(String url, String filename) throws IOException;

    public void checkSaveFolder() throws IOException {
        checkSaveFolder(saveFolder);
    }

    public void checkSaveFolder(String folder) throws IOException {
        Path path = Paths.get(folder);
        boolean exists = Files.exists(path);
        if (!exists) {
            Files.createDirectories(path);
        }
    }
}
